package com.flying.pas.security.model;

import java.util.Date;
import java.util.List;

import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Property;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;

@SuppressWarnings("serial")
@Meta(id="t_user",title="", table="t_user", primaryKeys={"user_id"})
public class User extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "t_user";
	
	public final static String CREATE_DATE = "create_date";
	public final static String CREATOR = "creator";
	public final static String MAIL = "mail";
	public final static String MOBILE = "mobile";
	public final static String ORG_ID = "org_id";
	public final static String ORG_CODE = "org_code";
	public final static String PASSWORD = "password";
	public final static String REAL_NAME = "real_name";
	public final static String REMARKS = "remarks";
	public final static String UPDATE_DATE = "update_date";
	public final static String UPDATOR = "updator";
	public final static String USER_ID = "user_id";
	public final static String USERNAME = "username";
	
	@Param(value=USER_ID,   required=true,   maxlength=0,	desc="用户ID" , 
			generator="com.flying.pas.model.User.userId", 
			props= {@Property(name="type",value="hidden")} )
	private Long userId;
	
	@Param(value=USERNAME,   required=true,   maxlength=40,	desc="登录名", 
			props= {@Property(name="condition",value="true")}  )
	private String username;
	
	@Param(value=REAL_NAME,   required=false,   maxlength=50,	desc="实名", 
			props= {@Property(name="condition",value="true")} )
	private String realName;
	
	@Param(value=MAIL,   required=false,   maxlength=100,	desc="邮箱" )
	private String mail;
	
	@Param(value=MOBILE,   required=false,   maxlength=20,	desc="手机" )
	private String mobile;
	
	@Param(value=ORG_ID,   required=false,   desc="组织机构ID", 
			props= {@Property(name="type",value="hidden")} )
	private Long orgId;
	
	@Param(value=ORG_CODE,   required=false,   maxlength=200,	desc="组织机构代码")
	private String orgCode;
	
	@Param(value=PASSWORD,   required=false,   maxlength=50,	desc="密码" )
	private String password;
	
	@Param(value=REMARKS,   required=false,   maxlength=200,	desc="说明" )
	private String remarks;
	
	@Param(value=CREATE_DATE,   required=false,   maxlength=0,	desc="创建时间", 
			props= {@Property(name="type",value="date")} )
	private Date createDate;
	
	@Param(value=CREATOR,   required=false,   maxlength=100,	desc="创建人" )
	private String creator;
	
	@Param(value=UPDATE_DATE,   required=false,   maxlength=0,	desc="修改时间", 
			props= {@Property(name="type",value="date")} )
	private Date updateDate;
	
	@Param(value=UPDATOR,   required=false,   maxlength=100,	desc="修改人" )
	private String updator;
	
	@ServiceField(serviceId="RoleService:findByUserId", params={@ServiceFieldParam(param=USER_ID, value="$"+USER_ID)}, valueAttribute="rows")
	@Param(value="roles",   required=false,   maxlength=400,	desc="子菜单" )
	private List<Role> roles;
	
	
	public Date getCreateDate() {
		return this.createDate;
	}
	
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	public String getCreator() {
		return this.creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	public String getMail() {
		return this.mail;
	}
	
	public void setMail(String mail) {
		this.mail = mail;
	}
	
	public String getMobile() {
		return this.mobile;
	}
	
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	public String getPassword() {
		return this.password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getRealName() {
		return this.realName;
	}
	
	public void setRealName(String realName) {
		this.realName = realName;
	}
	
	public Long getOrgId() {
		return orgId;
	}

	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public Date getUpdateDate() {
		return this.updateDate;
	}
	
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	
	public String getUpdator() {
		return this.updator;
	}
	
	public void setUpdator(String updator) {
		this.updator = updator;
	}
	
	public Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	
	public String getUsername() {
		return this.username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public Long[] getRoleIds() {
		List<Role> roles = this.getRoles();
		return roles == null?null: roles.stream().map(x -> x.getRoleId()).toArray(Long[]::new);
	}
	
	public String[] getRoleNames() {
		List<Role> roles = this.getRoles();
		return roles == null?null: roles.stream().map(x -> x.getName()).toArray(String[]::new);
	}

}